#ifndef GUIOFSINK_H
#define GUIOFSINK_H

#include <QMainWindow>

#include <QMap>
#include <QUdpSocket>
namespace Ui {
    class GUIOfSink;
}
class QListWidgetItem;
class DatabaseOperation;

class AdapterTelnet : public QMainWindow

{
    Q_OBJECT

public:
    explicit AdapterTelnet(QWidget *parent = 0);
    ~AdapterTelnet();

private slots:
    void on_pushButtonOK_clicked();
    void on_listWidgetNodesToConnect_itemChanged(QListWidgetItem *item);
    void on_listWidgetNodesToConnect_itemPressed(QListWidgetItem *item);

    void on_listWidgetNodesNotWork_itemClicked(QListWidgetItem *item);

    void on_listWidgetNodesNotWork_itemPressed(QListWidgetItem *item);

    void on_listWidgetNodesToConnect_itemClicked(QListWidgetItem *item);

    void on_listWidgetNodesNotWork_itemChanged(QListWidgetItem *item);

    void slotNodeFromNotWorkList2ToConnectList(QByteArray nodeIP,qint64 subAddr);
    void slotNodeFromToConnectList2NotWorkList(QByteArray nodeIP,qint64 subAddr);

    void slotThreadDestroyed(QByteArray nodeIP,qint64 subAddr);
    void slotTelnetDisconnectedTemporarily(QByteArray nodeIP,qint64 subAddr);
    void slotTelnetConnected(QByteArray nodeIP, qint64 subAddr);

    void slotShowInfoToTextEdit(QByteArray text);
    void slotShowInfoToErrorTextEdit(QByteArray text);

    void slotPacketReady(QByteArray packet);
    void slotProcessUDPDatagrams();
    void on_pushButtonClearTextEdit_clicked();

    void on_pushButtonAbout_clicked();

    void on_comboBoxNodeType_currentIndexChanged(const QString &arg1);

    void on_listWidgetNodesConnected_itemClicked(QListWidgetItem *item);

    void on_pushButtonExit_clicked();

    void on_pushButtonHide_clicked();

    void on_spinBoxPort_valueChanged(int arg1);

signals:
    //节点从notworklist拖到toconnectlist时，发射该信号。注意虚拟节点的处理
    void sigNodeFromNotWorkList2ToConnectList(QByteArray nodeIP,qint64 subAddr);
    //节点从toconnectList拖到notworklist时，发射该信号
    void sigNodeFromToConnectList2NotWorkList(QByteArray nodeIP,qint64 subAddr);
    //通知对应线程退出
    void sigExitThread(QByteArray nodeIP,qint64 subAddr);
    void sigShowInfoToTextEdit(QByteArray text);

    void sigPacketToNodes(QByteArray packet,qint64 destSubAddr);
    void sigPacketNodeToServer(QByteArray datagram,QHostAddress GWIP,
             quint16  GWPort,bool isFromTcp); //GWIP是指Sink的IP，此处即为telnet适配器的IP

private:
    Ui::GUIOfSink *ui;
    QMap <QByteArray,QByteArray> mapIPName; //IP与节点名的映射
    QMap <QByteArray,qint64> mapIPAddr;//IP地址与节点mac（低7字节）的映射。需要注意虚拟节点的处理。
    bool listNodeNotWorkPressed,listNodeToConnectPressed;
    QByteArray textPressedInListToConnect;
    QList <QByteArray> listNodeIPNotWork,listNodeIPToConnect;

    QUdpSocket udpSocket;
    DatabaseOperation *dbo;

};

#endif // GUIOFSINK_H
